<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: SSH</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">SSH</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/lib/svengali/ssh_rb.html">
                lib/svengali/ssh.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000051">close</a>&nbsp;&nbsp;
      <a href="#M000053">exec</a>&nbsp;&nbsp;
      <a href="#M000052">exec!</a>&nbsp;&nbsp;
      <a href="#M000050">new</a>&nbsp;&nbsp;
      <a href="#M000054">wait_until_ssh_connectable</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">session</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">sftp_session</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000050" class="method-detail">
        <a name="M000050"></a>

        <div class="method-heading">
          <a href="#M000050" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(host,user_name=nil,password=nil,private_key_path=nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000050-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000050-source">
<pre>
<span class="ruby-comment cmt"># File lib/svengali/ssh.rb, line 19</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">host</span>,<span class="ruby-identifier">user_name</span>=<span class="ruby-keyword kw">nil</span>,<span class="ruby-identifier">password</span>=<span class="ruby-keyword kw">nil</span>,<span class="ruby-identifier">private_key_path</span>=<span class="ruby-keyword kw">nil</span>)
    <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">user_name</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">password</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">private_key_path</span>
      <span class="ruby-ivar">@user_name</span> = <span class="ruby-identifier">user_name</span>
      <span class="ruby-ivar">@passphrase</span> = <span class="ruby-identifier">password</span>
      <span class="ruby-ivar">@private_key_path</span> = <span class="ruby-identifier">private_key_path</span>
    <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">user_name</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">password</span>
      <span class="ruby-ivar">@user_name</span> = <span class="ruby-identifier">user_name</span>
      <span class="ruby-ivar">@password</span> = <span class="ruby-identifier">password</span>
      <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">host</span>)
    <span class="ruby-keyword kw">else</span> <span class="ruby-comment cmt">#substitute of constructor which has no argument</span>
      <span class="ruby-ivar">@host</span> = <span class="ruby-identifier">host</span>
      <span class="ruby-ivar">@terminator</span> = <span class="ruby-value str">&quot;&quot;</span>

      <span class="ruby-identifier">wait_until_ssh_connectable</span>(<span class="ruby-constant">CLibIPAddr</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">host</span>))

      <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@user_name</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@password</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@private_key_path</span> <span class="ruby-comment cmt">#if initialized with private_key_path, user_name and password</span>
        <span class="ruby-identifier">debug_p</span> <span class="ruby-value str">&quot;Try Net::SSH.start()!&quot;</span>
        <span class="ruby-ivar">@session</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">SSH</span>.<span class="ruby-identifier">start</span>(<span class="ruby-ivar">@host</span>, <span class="ruby-ivar">@user_name</span>,<span class="ruby-identifier">:passphrase</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@passphrase</span>, <span class="ruby-identifier">:keys</span> =<span class="ruby-operator">&gt;</span> [ <span class="ruby-ivar">@private_key_path</span> ] )
      <span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@user_name</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@password</span> <span class="ruby-comment cmt">#if initialized with user_name and password</span>
        <span class="ruby-identifier">debug_p</span> <span class="ruby-value str">&quot;Try Net::SSH.start()!&quot;</span>
        <span class="ruby-ivar">@session</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">SSH</span>.<span class="ruby-identifier">start</span>(<span class="ruby-ivar">@host</span>, <span class="ruby-ivar">@user_name</span>,<span class="ruby-identifier">:password</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@password</span>)
      <span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@user_name</span> <span class="ruby-comment cmt">#if initialized with user_name</span>
        <span class="ruby-identifier">debug_p</span> <span class="ruby-value str">&quot;Try Net::SSH.start()!&quot;</span>        
        <span class="ruby-ivar">@session</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">SSH</span>.<span class="ruby-identifier">start</span>(<span class="ruby-ivar">@host</span>, <span class="ruby-ivar">@user_name</span>)
      <span class="ruby-keyword kw">end</span>
      <span class="ruby-identifier">debug_p</span> <span class="ruby-value str">&quot;Net::SSH.start finished.&quot;</span>
      <span class="ruby-ivar">@sftp_session</span> = <span class="ruby-ivar">@session</span>.<span class="ruby-identifier">sftp</span>.<span class="ruby-identifier">connect</span>()
    <span class="ruby-keyword kw">end</span>
  <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000051" class="method-detail">
        <a name="M000051"></a>

        <div class="method-heading">
          <a href="#M000051" class="method-signature">
          <span class="method-name">close</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000051-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000051-source">
<pre>
<span class="ruby-comment cmt"># File lib/svengali/ssh.rb, line 49</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">close</span>
    <span class="ruby-ivar">@session</span>.<span class="ruby-identifier">close</span>()
  <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000053" class="method-detail">
        <a name="M000053"></a>

        <div class="method-heading">
          <a href="#M000053" class="method-signature">
          <span class="method-name">exec</span><span class="method-args">(command_str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
return value : nothing
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000053-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000053-source">
<pre>
<span class="ruby-comment cmt"># File lib/svengali/ssh.rb, line 82</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">exec</span>(<span class="ruby-identifier">command_str</span>)
    <span class="ruby-identifier">debug_p</span> <span class="ruby-node">&quot;exec -&gt; \&quot;#{command_str}\&quot;&quot;</span>

    <span class="ruby-ivar">@session</span>.<span class="ruby-identifier">exec</span>(<span class="ruby-identifier">command_str</span>)
  <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000052" class="method-detail">
        <a name="M000052"></a>

        <div class="method-heading">
          <a href="#M000052" class="method-signature">
          <span class="method-name">exec!</span><span class="method-args">(command_str,time_out = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
return value : String of stdout or stderr
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000052-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000052-source">
<pre>
<span class="ruby-comment cmt"># File lib/svengali/ssh.rb, line 58</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">exec!</span>(<span class="ruby-identifier">command_str</span>,<span class="ruby-identifier">time_out</span> = <span class="ruby-keyword kw">nil</span>)
    <span class="ruby-identifier">debug_p</span> <span class="ruby-node">&quot;exec! -&gt; \&quot;#{command_str}\&quot;&quot;</span>

      <span class="ruby-keyword kw">begin</span>
        <span class="ruby-identifier">timeout</span>(<span class="ruby-identifier">time_out</span>) <span class="ruby-keyword kw">do</span>
          <span class="ruby-identifier">return_val</span> = <span class="ruby-value str">&quot;&quot;</span>
          <span class="ruby-ivar">@session</span>.<span class="ruby-identifier">exec!</span>(<span class="ruby-identifier">command_str</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">ch</span>, <span class="ruby-identifier">stream</span>, <span class="ruby-identifier">data</span><span class="ruby-operator">|</span>
            <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">stream</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:stdout</span>
              <span class="ruby-identifier">return_val</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">data</span>
            <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">stream</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:stderr</span>
              <span class="ruby-identifier">return_val</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">data</span>
            <span class="ruby-keyword kw">end</span>
          }
          <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">return_val</span>
        <span class="ruby-keyword kw">end</span>
      <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">TimeoutError</span>
        <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
      <span class="ruby-keyword kw">end</span>
  <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000054" class="method-detail">
        <a name="M000054"></a>

        <div class="method-heading">
          <a href="#M000054" class="method-signature">
          <span class="method-name">wait_until_ssh_connectable</span><span class="method-args">(host)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000054-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000054-source">
<pre>
<span class="ruby-comment cmt"># File lib/svengali/ssh.rb, line 88</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">wait_until_ssh_connectable</span>(<span class="ruby-identifier">host</span>)
      <span class="ruby-comment cmt"># waits until ensure that ssh connection can be accept</span>
      <span class="ruby-keyword kw">while</span>(<span class="ruby-identifier">is_ssh_connectable</span>(<span class="ruby-identifier">host</span>) <span class="ruby-operator">==</span> <span class="ruby-keyword kw">false</span>)
        <span class="ruby-identifier">sleep</span>(<span class="ruby-value">1</span>)
      <span class="ruby-keyword kw">end</span>
  <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>